package org.groupg.practice;

import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.SimpleDirectedGraph;
import org.jgrapht.traverse.DepthFirstIterator;

public class DAGExample {
    public static void main(String[] args) {
        // 创建一个有向图
        Graph<String, DefaultWeightedEdge> graph = new SimpleDirectedGraph<>(DefaultWeightedEdge.class);

        // 添加节点和边
        graph.addVertex("A");
        graph.addVertex("B");
        graph.addVertex("C");
        graph.addVertex("D");

        graph.addVertex("E");
        graph.addVertex("F");
        graph.addVertex("G");
        graph.addVertex("H");
        graph.addEdge("A", "B");
        graph.addEdge("B", "C");
        graph.addEdge("B", "D");

        // 遍历图（使用深度优先搜索）
        new DepthFirstIterator<>(graph).forEachRemaining(vertex -> {
            System.out.println("Visited vertex: " + vertex);
        });
    }
}